<!DOCTYPE html>
<html>
<head>
    <title>测试报告</title>
    <style>
        table {
            border-collapse: collapse;
            width: 100%;
        }

        th, td {
            border: 1px solid black;
            padding: 8px;
            text-align: left;
        }
    </style>
</head>
<body>
<h1>测试报告</h1>

<h2>基本信息</h2>
<p>日期时间: <span id="datetime"></span></p>
<p>总测试数: <span id="totalTests"></span></p>
<p>失败测试数: <span id="failedTests"></span></p>

<h2>失败用例</h2>
<table>
    <thead>
    <tr>
        <th>用例名称</th>
        <th>失败原因</th>
    </tr>
    </thead>
    <tbody id="failedCasesTable"></tbody>
</table>

<h2>基准测试</h2>
<h3>上次musl数据</h3>
<table id="previousMuslBenchmarkTable">
    <thead>
    <tr>
        <th>Benchmark</th>
        <th>Time</th>
        <th>Cpu</th>
        <th>Iterations</th>
        <th>UserCounters</th>
    </tr>
    </thead>
    <tbody></tbody>
</table>

<h3>本次musl数据</h3>
<table id="currentMuslBenchmarkTable">
    <thead>
    <tr>
        <th>Benchmark</th>
        <th>Time</th>
        <th>Cpu</th>
        <th>Iterations</th>
        <th>UserCounters</th>
    </tr>
    </thead>
    <tbody></tbody>
</table>

<h3>上次bionic数据</h3>
<table id="previousBionicBenchmarkTable">
    <thead>
    <tr>
        <th>Benchmark</th>
        <th>Time</th>
        <th>Cpu</th>
        <th>Iterations</th>
        <th>UserCounters</th>
    </tr>
    </thead>
    <tbody></tbody>
</table>

<h3>本次bionic数据</h3>
<table id="currentBionicBenchmarkTable">
    <thead>
    <tr>
        <th>Benchmark</th>
        <th>Time</th>
        <th>Cpu</th>
        <th>Iterations</th>
        <th>UserCounters</th>
    </tr>
    </thead>
    <tbody></tbody>
</table>

<script>
    var jsonData = {
        "datetime": "",
        "xts": {
            "total": 1555,
            "failureNum": 10,
            "failureTestCase": [
                {
                    "name": "case1",
                    "reason": "reason1"
                },
                {
                    "name": "case2",
                    "reason": "reason2"
                }
            ]
        },
        "benchmark": {
            "previousMuslBenchmark": [
                {
                    "Benchmark": "",
                    "Time": "",
                    "Cpu": "",
                    "Iterations": 23,
                    "UserCounters": ""
                }
            ],
            "muslBenchmark": [
                {
                    "Benchmark": "",
                    "Time": "",
                    "Cpu": "",
                    "Iterations": 23,
                    "UserCounters": ""
                }
            ],
            "previousBionicBenchmark": [
                {
                    "Benchmark": "",
                    "Time": "",
                    "Cpu": "",
                    "Iterations": 5654,
                    "UserCounters": ""
                }
            ],
            "bionicBenchmark": [
                {
                    "Benchmark": "",
                    "Time": "",
                    "Cpu": "",
                    "Iterations": 23,
                    "UserCounters": ""
                }
            ]
        }
    };

    document.getElementById('datetime').textContent = jsonData.datetime;
    document.getElementById('totalTests').textContent = jsonData.xts.total;
    document.getElementById('failedTests').textContent = jsonData.xts.failureNum;

    var failedCasesTableElement = document.getElementById('failedCasesTable');
    var failedCases = jsonData.xts.failureTestCase;

    for (var i = 0; i < failedCases.length; i++) {
        var row = document.createElement('tr');

        var nameCell = document.createElement('td');
        nameCell.textContent = failedCases[i].name;
        row.appendChild(nameCell);

        var reasonCell = document.createElement('td');
        reasonCell.textContent = failedCases[i].reason;
        row.appendChild(reasonCell);

        failedCasesTableElement.appendChild(row);
    }

    var previousMuslBenchmarkTableElement = document.getElementById('previousMuslBenchmarkTable');
    var previousMuslBenchmarkData = jsonData.benchmark.previousMuslBenchmark;

    for (var j = 0; j < previousMuslBenchmarkData.length; j++) {
        var row = document.createElement('tr');

        var benchmarkCell = document.createElement('td');
        benchmarkCell.textContent = previousMuslBenchmarkData[j].Benchmark;
        row.appendChild(benchmarkCell);

        var timeCell = document.createElement('td');
        timeCell.textContent = previousMuslBenchmarkData[j].Time;
        row.appendChild(timeCell);

        var cpuCell = document.createElement('td');
        cpuCell.textContent = previousMuslBenchmarkData[j].Cpu;
        row.appendChild(cpuCell);

        var iterationsCell = document.createElement('td');
        iterationsCell.textContent = previousMuslBenchmarkData[j].Iterations;
        row.appendChild(iterationsCell);

        var userCountersCell = document.createElement('td');
        userCountersCell.textContent = previousMuslBenchmarkData[j].UserCounters;
        row.appendChild(userCountersCell);

        previousMuslBenchmarkTableElement.appendChild(row);
    }

    var currentMuslBenchmarkTableElement = document.getElementById('currentMuslBenchmarkTable');
    var currentMuslBenchmarkData = jsonData.benchmark.muslBenchmark;

    for (var k = 0; k < currentMuslBenchmarkData.length; k++) {
        var row = document.createElement('tr');

        var benchmarkCell = document.createElement('td');
        benchmarkCell.textContent = currentMuslBenchmarkData[k].Benchmark;
        row.appendChild(benchmarkCell);

        var timeCell = document.createElement('td');
        timeCell.textContent = currentMuslBenchmarkData[k].Time;
        row.appendChild(timeCell);

        var cpuCell = document.createElement('td');
        cpuCell.textContent = currentMuslBenchmarkData[k].Cpu;
        row.appendChild(cpuCell);

        var iterationsCell = document.createElement('td');
        iterationsCell.textContent = currentMuslBenchmarkData[k].Iterations;
        row.appendChild(iterationsCell);

        var userCountersCell = document.createElement('td');
        userCountersCell.textContent = currentMuslBenchmarkData[k].UserCounters;
        row.appendChild(userCountersCell);

        currentMuslBenchmarkTableElement.appendChild(row);
    }

    var previousBionicBenchmarkTableElement = document.getElementById('previousBionicBenchmarkTable');
    var previousBionicBenchmarkData = jsonData.benchmark.previousBionicBenchmark;

    for (var l = 0; l < previousBionicBenchmarkData.length; l++) {
        var row = document.createElement('tr');

        var benchmarkCell = document.createElement('td');
        benchmarkCell.textContent = previousBionicBenchmarkData[l].Benchmark;
        row.appendChild(benchmarkCell);

        var timeCell = document.createElement('td');
        timeCell.textContent = previousBionicBenchmarkData[l].Time;
        row.appendChild(timeCell);

        var cpuCell = document.createElement('td');
        cpuCell.textContent = previousBionicBenchmarkData[l].Cpu;
        row.appendChild(cpuCell);

        var iterationsCell = document.createElement('td');
        iterationsCell.textContent = previousBionicBenchmarkData[l].Iterations;
        row.appendChild(iterationsCell);

        var userCountersCell = document.createElement('td');
        userCountersCell.textContent = previousBionicBenchmarkData[l].UserCounters;
        row.appendChild(userCountersCell);

        previousBionicBenchmarkTableElement.appendChild(row);
    }

    var currentBionicBenchmarkTableElement = document.getElementById('currentBionicBenchmarkTable');
    var currentBionicBenchmarkData = jsonData.benchmark.bionicBenchmark;

    for (var m = 0; m < currentBionicBenchmarkData.length; m++) {
        var row = document.createElement('tr');

        var benchmarkCell = document.createElement('td');
        benchmarkCell.textContent = currentBionicBenchmarkData[m].Benchmark;
        row.appendChild(benchmarkCell);

        var timeCell = document.createElement('td');
        timeCell.textContent = currentBionicBenchmarkData[m].Time;
        row.appendChild(timeCell);

        var cpuCell = document.createElement('td');
        cpuCell.textContent = currentBionicBenchmarkData[m].Cpu;
        row.appendChild(cpuCell);

        var iterationsCell = document.createElement('td');
        iterationsCell.textContent = currentBionicBenchmarkData[m].Iterations;
        row.appendChild(iterationsCell);

        var userCountersCell = document.createElement('td');
        userCountersCell.textContent = currentBionicBenchmarkData[m].UserCounters;
        row.appendChild(userCountersCell);

        currentBionicBenchmarkTableElement.appendChild(row);
    }
</script>
</body>
</html>
